package com.btex.app.push;

import android.content.Context;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.util.PreferencesCookieStore;
import com.btex.app.Config;
import com.btex.app.tools.CookieTool;
import com.btex.app.tools.LogUtil;
import com.btex.app.tools.SharedPreferencesUtil;
import com.btex.app.tools.Tools;

/**
 * Created by wcx on 16/3/30.
 */
public class SendPushInfo {
    public SendPushInfo(String channelId,Context cxt, final String chanelName) {
        SharedPreferencesUtil sp = SharedPreferencesUtil.getSharedPreferences(cxt);
        sp.putString(chanelName+"ID",channelId);  //存储channelID
        PreferencesCookieStore cookieStore = CookieTool.getCookieStore(cxt, sp);
        RequestParams params = new RequestParams();
        params.addQueryStringParameter("device_model",android.os.Build.MODEL+"");
        params.addQueryStringParameter("channel_id",channelId);
        params.addQueryStringParameter("device_type",3+"");
        params.addQueryStringParameter("channel_name",chanelName);
        params.addQueryStringParameter("app_version", Tools.getVersion(cxt));
        params.addHeader("myclient", "android");
        LogUtil.i("SendPushInfo","url:"+Config.URL_SET_PUSH_INFO+"?device_model="+android.os.Build.MODEL+
                "&channel_id="+channelId+"&device_type="+3+""+"&channel_name="+chanelName+"&app_version="+ Tools.getVersion(cxt));

        new HttpUtils().configCookieStore(cookieStore).send(HttpRequest.HttpMethod.GET, Config.URL_SET_PUSH_INFO, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                LogUtil.i("SendPushInfo","PushInfo:"+chanelName+"   responseInfo:"+responseInfo.result.toString());
            }

            @Override
            public void onFailure(HttpException error, String msg) {

            }
        });
    }
}
